package com.sikaryofficial.system.api.factory;

import com.sikaryofficial.common.core.domain.R;
import com.sikaryofficial.system.api.RemoteFileMD5Service;
import com.sikaryofficial.system.api.domain.SysFile;
import com.sikaryofficial.system.api.model.FileMd5VO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * FileMD5服务降级处理
 *
 * @author qinjinyuan
 */
@Component
public class RemoteFileMD5FallbackFactory implements FallbackFactory<RemoteFileMD5Service> {
    private static final Logger log = LoggerFactory.getLogger(RemoteFileMD5FallbackFactory.class);

    @Override
    public RemoteFileMD5Service create(Throwable throwable) {
        log.error("FileMD5服务调用失败:{}", throwable.getMessage());
        return new RemoteFileMD5Service() {
            /**
             * 获取文件MD5详细信息
             *
             * @param md5
             */
            @Override
            public R<SysFile> getInfo(String md5) {
                return R.fail("获取FileMD5失败:" + throwable.getMessage());
            }

            /**
             * 新增文件MD5
             *
             * @param fileMd5
             */
            @Override
            public R<Boolean> add(FileMd5VO fileMd5) {
                return R.fail("添加FileMD5失败:" + throwable.getMessage());
            }
        };
    }
}
